<%--
 *  File:    CityCodeSummary.jsp
 *  @Author: StephenLiu
 *  Date:    Tuesday, July 15, 2003

 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>

<%@ include file="/inc/SessionTimeout.inc" %>

<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.*" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  Category cat = Category.getInstance("jsp.CityCodeSummary");
  String strModuleName = "IMG";
  String privilegeCode = "Z0814";
  String strTableName = "ovcity";
%>

<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<%@ include file="/rpt/ReportURL.inc"%>

<html>
<head>
<title>CityCodeSummary</title>
<PageFlow:CheckPageFlow pageName="citysummary"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<%@ include file="/inc/SumDiv.inc" %>
<script language="JavaScript" src="../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../js/ScriptLib.js"></script>
<script language="JavaScript" src="../js/SummaryDivision.js"></script>
<%
  Vector totalSummary = (Vector) pageContext.getAttribute("totalsummary");
  if (totalSummary == null) totalSummary = new Vector();
  String whetherarea=request.getParameter("whetherarea"); 
  if(whetherarea == null) whetherarea="";
  String whethercover=request.getParameter("whethercover");
  if(whethercover == null) whethercover="";
  String whetherismultiple=request.getParameter("whetherismultiple");
  if(whetherismultiple == null) whetherismultiple="";
%>
<script language="JavaScript">
function page_summary(actionvalue, orderbyname) {
  //change_whetherarea();
  //change_whethercover();
  var editform = summaryPrepare(document.frm, actionvalue, orderbyname);
  editform.action = "CityCodeSummary.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}
function checkedNumber(ids) {
  if(ids == null)
    return 0;
  if(ids.length == null) {
    if(ids.checked)
      return 1;
    else
      return 0;
  }
  var count = 0;
  for(var i = 0; i < ids.length; i ++) {
    if(ids[i].checked)
      count ++;
  }
  return count;
}
function page_add() {
  self.location.href = "CityCodeEdit.jsp?<%= OvalTools.randomURL() %>";
}
function page_edit() {
  var cityid;
  switch (checkedNumber(frm.deletecodes)) {
    case 0:
      alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
      return;
    case 1:
      if (frm.deletecodes.length == null)
        cityid = frm.cityid0.value;
      else {
        for (var i = 0; frm.deletecodes[i].checked == false; i ++);
        cityid = eval("frm.cityid" + i).value;
      }
      break;
    default:
      alert("<%= message.getMessageDesc("MUST_SELECT_ONE_AND_ONLY") %>");
      return;
  }
  self.location.href = "CityCodeEdit.jsp?<%= OvalTools.randomURL() %>&cityid=" + cityid;
}
function page_delete() {
  if (checkedNumber(frm.deletecodes) == 0) {
    alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
    return;
  }
  frm.actionname.value = "delete";
  frm.target.value = "_self";
  isRunning = true;
  frm.submit();
}

function page_save(){
  if(!checkForm(frm)) return;
  frm.actionname.value = "save";
  frm.target.value = "_self";
  isRunning = true;
  frm.submit();
}
function change_status(num){
    var istargets=eval('document.frm.istargets'+num);
    var istarget=eval('document.frm.istarget'+num);

	 if(istarget.value == "" || istarget.value == null ){
	    istarget.value='Y';
		return ;
	 }else{
	  if(istarget.value == "N"){
		istarget.value='Y';
		istargets.checked=true;
		return ;
	  }
	  if(istarget.value == "Y"){
		istarget.value='N';
		istargets.checked=false;
		return ;
	  }
	 }
	
}

function change_status2(num){
    var ismultiples=eval('document.frm.ismultiples'+num);
    var ismultiple=eval('document.frm.ismultiple'+num);

	 if(ismultiple.value == "" || ismultiple.value == null ){
	    ismultiple.value='Y';
		return ;
	 }else{
	  if(ismultiple.value == "N"){
		ismultiple.value='Y';
		ismultiples.checked=true;
		return ;
	  }
	  if(ismultiple.value == "Y"){
		ismultiple.value='N';
		ismultiples.checked=false;
		return ;
	  }
	 }
	
}
function change_whetherarea(){
    var whetherarea1=eval('document.frm.whetherarea1');
    var whetherarea=eval('document.frm.whetherarea');
    /*if(whetherarea1.checked){
      whetherarea.value='Y';
    }else {
     whetherarea.value='N';
    }*/
   if(whetherarea1.value==1){
      whetherarea.value='Y';
    }else if(whetherarea1.value==2){
     whetherarea.value='N';
    }else {
     whetherarea.value='';
    }
}
function change_whethermultiple(){
    var whetherismultiple1=eval('document.frm.whetherismultiple1');
    var whetherismultiple=eval('document.frm.whetherismultiple');
    /*if(whetherismultiple1.checked){
      whetherismultiple.value='Y';
    }else {
     whetherismultiple.value='N';
    }*/
   if(whetherismultiple1.value==1){
      whetherismultiple.value='Y';
    }else if(whetherismultiple1.value==2){
     whetherismultiple.value='N';
    }else {
     whetherismultiple.value='';
    }
}

function change_whethercover(){
    var whethercover1=eval('document.frm.whethercover1');
    var whethercover=eval('document.frm.whethercover');
    if(whethercover1.value==1){
      whethercover.value='Y';
    }else if(whethercover1.value==2){
     whethercover.value='N';
    }else {
     whethercover.value='';
    }
}
function onload(){
          <%
          for (int i =0;i < totalSummary.size();i++){
              HashMap cityinfo=(HashMap)totalSummary.get(i);
              String istarget = "";
              String iscover="";
              String ismultiple="";
              String editflag="";
              Integer cityid;
              Integer parentcityid;
              cityid=(Integer)cityinfo.get("cityid");
              parentcityid=(Integer)cityinfo.get("parentcityid1");
              //System.out.println("cityid="+cityid);
              //System.out.println("parentcityid="+parentcityid);
              istarget=(String)cityinfo.get("istarget");
              iscover=(String)cityinfo.get("iscover");
              editflag=(String)cityinfo.get("editflag");
              ismultiple=(String)cityinfo.get("ismultiple");
              if(istarget == null || istarget ==""){istarget="N";}
              if(iscover == null || iscover ==""){iscover="N";}
              if(editflag == null || editflag ==""){editflag="N";}
              if(ismultiple == null || ismultiple ==""){ismultiple="N";}
              if(istarget.equals("Y")){
           %>
                eval('document.frm.istargets'+<%=i %>).checked=true;
                eval('document.frm.istarget'+<%=i %>).value="Y";
           <% 
            }else{%>
             eval('document.frm.istarget'+<%=i %>).value="N";
           <%
           }
              if(ismultiple.equals("Y")){
           %>
              eval('document.frm.ismultiples'+<%=i %>).checked=true;
              eval('document.frm.ismultiple'+<%=i %>).value="Y";
           <%}else{%>
              eval('document.frm.ismultiple'+<%=i %>).value="N";
           <%
           }if(iscover.equals("Y")){
           %>
             eval('document.frm.isbale'+<%=i %>).value=1;
           <%}else{%>
             eval('document.frm.isbale'+<%=i %>).value=2;
           <%}
            if(editflag.equals("N")){
            	 //System.out.println(cityid != parentcityid);
            	 //System.out.println(parentcityid.equals(cityid));
            	if(!parentcityid.equals(cityid)){
           %>
              
             eval('document.frm.istargets'+<%=i %>).disabled=true;
             eval('document.frm.istargets'+<%=i %>).style.backgroundColor="#b4b4b4";
           <%
            	}
             }
           } 
          %>
          
          //document.frm.whetherarea1.checked=false;
          //document.frm.whetherismultiple1.checked=false;
          var whetherarea='<%=request.getParameter("whetherarea") %>';
          var whethercover='<%=request.getParameter("whethercover") %>';
          var whetherismultiple='<%=request.getParameter("whetherismultiple") %>';
          if(whetherarea == 'Y'){
             //document.frm.whetherarea1.checked=true;
             document.frm.whetherarea1.options[1].selected=true;
          }
          if(whetherarea == 'N'){
             //document.frm.whetherarea1.checked=true;
             document.frm.whetherarea1.options[2].selected=true;
          }
          if(whetherismultiple == 'Y'){
             //document.frm.whetherismultiple1.checked=true;
             document.frm.whetherismultiple1.options[1].selected=true;
          }
          if(whetherismultiple == 'N'){
             //document.frm.whetherismultiple1.checked=true;
              document.frm.whetherismultiple1.options[2].selected=true;
          }
          if(whethercover == 'Y'){
             document.frm.whethercover1.options[1].selected=true;
          }
          if(whethercover == 'N'){
             document.frm.whethercover1.options[2].selected=true;
          }
     }
     
function page_clear(){
	document.frm.whetherarea1.options[0].selected=true;
	document.frm.whetherarea.value="";
	document.frm.whetherismultiple1.options[0].selected=true;
	document.frm.whetherismultiple.value="";
	document.frm.whethercover1.options[0].selected=true;
	document.frm.whethercover.value="";
	document.frm.searchname.value="";
	document.frm.searchvalue.value="";
	
}

function exportExcel(){
	 window.open("<%= reportURL %>/servlet/ExcecuteReport/CityCodeReport.sox?__format=xlsx&__folder=/ovalreport");
	}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="frm" method="post" action="../Dispatcher">
   <input type="hidden" name="pagename" value="citysummary">
   <input type="hidden" name="actionname">
   <input type="hidden" name="flags" value="0">
   <input type="hidden" name="numrows" value="<%=totalSummary.size() %>">
   <custom:hidden  property="whetherarea" value="<%=whetherarea %>"/>
   <custom:hidden  property="whethercover" value="<%=whethercover %>"/>
   <custom:hidden  property="whetherismultiple" value="<%=whetherismultiple %>"/>
<%@include file="/inc/PageLocation.inc" %>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="summary_top"></td>
  </tr>
  <%@include file="/inc/SummarySearch.inc" %>
  <tr>
  <table>
    <tr>
    <td>&nbsp;</td>
    <td class="title_left"><%= label.getLabelName("L_WhetherMultiple") %>&nbsp;&nbsp;<!--<a onclick="change_whethermultiple();"><custom:checkbox  property="whetherismultiple1" /></a>--><custom:selectdic property="whetherismultiple1" dictType="YesOrNo"  defaultValueCost=" " defaultValue="---全部---" onchange="change_whethermultiple();"/></td>
    <td class="title_left"><%= label.getLabelName("L_WhetherArea") %>&nbsp;&nbsp;<!--  <a onclick="change_whetherarea();"><custom:checkbox  property="whetherarea1" /></a>--><custom:selectdic property="whetherarea1" dictType="YesOrNo"  defaultValueCost=" " defaultValue="---全部---" onchange="change_whetherarea();"/></td>
    <td class="title_left"><%= label.getLabelName("L_WhetherCover") %>&nbsp;&nbsp;<custom:selectdic property="whethercover1" dictType="YesOrNo"  defaultValueCost=" " defaultValue="---全部---" onchange="change_whethercover();"/></td>
    <td><button type="button" onclick="page_clear()" class="button1" name="re" value="clear"><%=label.getLabelName("L_Clear") %></button></td>
    </tr>
  </table>
  </tr>
</table>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr>
    <td>
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
        <tr class="deepblue-left" >
          <td width="21" class="title_center">&nbsp;</td>
          <td width="120" class="title_center"><a href="javascript:page_summary('orderby','citycode')"><%= label.getLabelName("L_CityCode") %></a></td>
          <%--<td class="title_center" width="113"><a href="javascript:page_summary('orderby','countryname')"><%= label.getLabelName("L_Country") %></a></td>--%>
          <td class="title_center" width="120"><%= label.getLabelName("L_Province") %></td>
          <td class="title_center" width="216"><a href="javascript:page_summary('orderby','cityname')"><%= label.getLabelName("L_CityName") %></a></td>
          <td class="title_center" width="216"><%= label.getLabelName("L_ParentCity") %></td>
          <td class="title_center" width="216"><%= label.getLabelName("L_WhetherMultiple") %></td>
          <td class="title_center" width="216"><%= label.getLabelName("L_WhetherArea") %></td>
          <td class="title_center" width="216"><%= label.getLabelName("L_WhetherCover") %></td>
          <td class="title_center" width="216"><%= label.getLabelName("L_CityType") %></td>
        </tr>
        <logic:iterate id="onecity" collection="<%= totalSummary %>" indexId="index">
        <%
          int i = index.intValue();
          String strClassType = "td-listrom";
          if(i % 2 == 0) strClassType = "none";
	      else strClassType = "td-listrom";
        %>
        <tr class="<%=JspHelper.filterNull( strClassType )%>"  onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'">
            <td>
            <!--<input type="checkbox" name="deletecodes" value="'<custom:write name="onecity" property="citycode"/>'" class="checkbox">-->
            &nbsp;
          </td>
          
          <td><custom:write name="onecity" property="citycode" nbsp="true"/></td>
          <%--<td><custom:write name="onecity" property="countryname" nbsp="true"/></td>--%>
          <td><custom:write name="onecity" property="regionname" nbsp="true"/></td>
          <td><custom:write name="onecity" property="cityname" nbsp="true"/></td>
          <td><custom:write name="onecity" property="parentcityname" nbsp="true"/></td>
          <td><custom:hidden name="onecity" property="ismultiple" colIndex="<%= index %>"/><a onclick="change_status2(<%=i %>)"><custom:checkbox  property="ismultiples" colIndex="<%=index %>"/></a></td>
          <td><custom:hidden name="onecity" property="istarget" colIndex="<%= index %>"/><a onclick="change_status(<%=i %>)"><custom:checkbox  property="istargets" colIndex="<%=index %>"/></a></td>
          <td><custom:selectdic property="isbale" dictType="YesOrNo"  defaultValueCost=" " colIndex="<%=index %>" disabled="true"/></td>
          <td> <custom:selectdic name="onecity" property="citytype" colIndex="<%=index %>" dictType="CityType" defaultValue="----" defaultValueCost=" " command="notnull" label="L_CityType"/></td>
          <custom:hidden name="onecity" property="cityid" colIndex="<%= index %>"/>
        </tr>
        </logic:iterate>
        <%@ include file="/inc/SummaryAction.inc" %>
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr>
          <td class="summary_top"></td>
        </tr>
        <tr>
          <td class="td_center">
            <!-- <a onclick="page_add()"><custom:button type="1" label="L_Add" imgsrc="add.gif" border="0" style="width:60"/></a> -->
            <% if (totalSummary.size() != 0){ %>
            <a onclick="page_save()"><custom:button type="1" label="L_Save" imgsrc="modify.gif" border="0" style="width:60"/></a>
            <!--<a onclick="page_delete()"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60"/></a> -->
            <a onclick="exportExcel();"><custom:button type="1" label="L_Execcd" imgsrc="delete.gif" border="0" style="width:60"/>
            <% } %>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<script type="text/javascript">
onload();
</script>
</form>
</body>
</html>
